package cn.fuxue.hrms.service.impl;

import cn.fuxue.hrms.common.base.AbstractService;
import cn.fuxue.hrms.common.dto.Login;
import cn.fuxue.hrms.common.entity.User;
import cn.fuxue.hrms.common.utils.Md5;
import cn.fuxue.hrms.mapper.LoginMapper;
import cn.fuxue.hrms.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

@Service
public class LoginServiceImpl extends AbstractService<Login,Integer> implements LoginService {
    private static String salt="hrms";

    @Autowired
    private LoginMapper loginMapper;

    @Autowired
    @Override
    public void setBaseMapper() {
        super.setBaseMapper(loginMapper);
    }



    @Override
    public User findUser(String username, String password) {
        String encrypt=null;
        try {
            encrypt= Md5.md5(password+salt);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return loginMapper.findUser(username,encrypt);
    }
}
